#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> ans;
vector<int> track;

void dfs(int x, int n, vector<vector<int>>& graph) {
    if (x == n - 1) {
        ans.push_back(track);
        return;
    }
    for (int i = 0; i < graph[x].size(); i++) {
        track.push_back(graph[x][i]);
        dfs(graph[x][i], n, graph);
        track.pop_back();
    }
}

vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
    dfs(0, graph.size(), graph);
    return ans;
}